<?php

namespace App\Service\UserCenter;

use App\Helpers\AliyunUtil;
use App\Helpers\DateUtil;
use App\Model\UserBlacklist;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 黑名单列表
 */
class BlacklistService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $users = UserBlacklist::getList($userId);
        $userIds = array_column($users, 'black_user_id');
        $usersInfo = UserProfile::getUsersProfile($userIds, true);
        $ret['list'] = [];
        foreach ($users as $item) {
            $blackUid = $item['black_user_id'];
            $profile = $usersInfo[$blackUid];
            $ret['list'][] = [
                'user_id' => $blackUid,
                'nick_name' => $profile['nick_name'],
                'gender' => $profile['gender'],
                'age' => DateUtil::dateDiff($profile['birthday'], date('Y-m-d'), 'Y'),
                'avatar' => AliyunUtil::IMG_HOST . $profile['avatar'],
                'add_time' => (string)$item['created_at'],
            ];
        }
        return $ret;
    }
}
